/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1160.breakaway.model;

import java.util.Vector;

/**
 *
 * @author Team 1160 Firebird Robotics (saketh kasibatla)
 */
public class ModelUpdater
{
    //protected ModelNotifier[] notifiers;

    private Object _lock;
    protected Vector _notifiers;
    protected Model _model;

    //public ModelUpdater(ModelNotifier[] notifiers){
    //    super();
    //    this.notifiers=notifiers;
    //}

    public ModelUpdater(Model model)
    {
        this._model     = model;
        this._lock      = new Object();
        this._notifiers = new Vector();
    }

    public void addNotifier(ModelNotifier notifier)
    {
        synchronized(this._lock)
        {
            if (!this._notifiers.contains(notifier))
            {
                this._notifiers.addElement(notifier);
            }
        }
    }

    public void removeNotifier(ModelNotifier notifier)
    {
        synchronized(this._lock)
        {
            if (this._notifiers.contains(notifier))
            {
                this._notifiers.removeElement(notifier);
            }
        }
    }




    public void updateModel()
    {
        synchronized(this._lock)
        {
            int size = this._notifiers.size();
            for (int i = 0; i < size; ++i)
            {
                ModelNotifier mn = (ModelNotifier) this._notifiers.elementAt(i);
                mn.updateModel(this._model);
            }
        }
    }


}
